<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/27
 * Time: 10:05
 */

namespace Home\Controller;

use Home\Common\Controller\CommonController;
use Think\Controller;

/**
 * Class SearchController
 * @package Home\Controller
 * 搜索功能
 */
class SearchController extends CommonController
{
    /**
     * 搜索功能
     */
    public  function  searchs(){
//        dd(I('post.gname'));die;
        if(!isset($_GET['gname'])){
            $gname=htmlspecialchars(I('post.gname'));
            $gname=addslashes($gname);
            $this->redirect("home/search/searchs/gname/".$gname);die;
        }else{
            $gname=I('get.gname');
            $gname=addslashes($gname);
        }
        if(isset($_GET['bid'])){
             $bid=I('get.bid');
            if($bid!=0){
                $map['sp_goods.bid']=$bid;
            }
        }
        $map['sp_goods.gname'] = array('like',"%{$gname}%");
        $goods=M('goods')->join("sp_product ON sp_goods.gid=sp_product.gid")->where($map)->group('sp_goods.gid')->select();
//        //超找所有分类
//        $soncate=M('category')->select();
//        $this->assign('soncate',$soncate);
        //查找该商品的所有品牌
        $maps['gname']=['like',"%{$gname}%"];
        $brand=M('brand')->join("sp_goods ON sp_brand.bid=sp_goods.bid")->where($maps)->group('sp_goods.bid')->select();
//        dd($brand);die;
//        dd($goods);
        $this->assign('goods',$goods);
        $this->assign('brand',$brand);
        $this->display();
    }

}